<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>短信内容配置管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <script src="../../layui/layui.js"></script>
    <script src="../../js/jquery-1.8.3.js"></script>
    <script src="../../js/util.js"></script>
    <script type="text/javascript">
        layui.use(['layer', 'table', 'form', 'jquery', 'element'], function () {
            var table = layui.table;
            var layer = layui.layer;
            var form = layui.form;
            var $ = layui.$;
            var user;
            //身份识别
            $(document).ready(function () {
                $.ajax({
                    type: 'post',
                    async: false,
                    url: '/util/findUser',
                    success: function (json) {
                        user = json;
                        if (json.duty == 1) {
                            $("#cityId").val(json.cityId);
                            $("#cityId").attr("disabled", true);
                            $("#shortname").attr("style", "display:none");
                            var data = selectMgrInfo(json.cityId);
                            appendMgr(data);
                            form.render();
                        } else if (json.duty == 2) {
                            $("#cityId").val(json.cityId);
                            $("#cityId").attr("disabled", true);
                            $("#shortname").attr("style", "display:none");
                            appendMgr(json.list);
                            form.render();
                        }
                    }, error: function () {
                        layer.msg('系统异常，请联系管理员处理!');
                    }
                });
            });

            var tableDate = {
                elem: "#table",//表格id
                id: "modelReload", //id
                url: '/content/find',
                method: 'post',
                request: {
                    pageName: 'page',
                    limitName: 'limit'
                },
                response: {
                    statusName: 'code',
                    statusCode: 0,
                    msgName: 'msg',
                    countName: 'count',
                    dataName: 'data'
                },
                page: true,
                count: "count",
                limit: 10,
                limits: [10, 20, 30, 40, 50],
                layout: ['prev', 'page', 'next'],
                prev: "上一页",
                next: "下一页",
                cols: [[ //表头
                    {field: 'cityName', title: '地市', width: 90}
                    , {field: 'name', title: '项目名称', width: 100}
                    , {field: 'stateName', title: '项目状态', width: 100}
                    , {field: 'templateStateName', title: '模板状态', width: 100}
                    , {field: 'content', title: '短信内容'}
                    , {field: 'createTime', title: '短信内容配置时间'}
                    , {field: 'newContent', title: '新短信内容'}
                    , {field: 'effectTime', title: '新短信内容生效时间'}
                    , {field: 'operation', title: '操作', toolbar: '#barDemo'}
                ]], done: function (res, curr, count) {
                }
            };
            table.render(tableDate);
            $('#query').on('click', function () {
                var mgrId = $("#mgrId").val();
                var cityId = $("#cityId").val();
                var mgrName = $("#mgrName").val();
                if (
                    mgrId == "" && user.duty == 2
                ) {
                    layer.msg("您必须选择一个项目");
                } else {
                    var index = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    table.reload('modelReload', {
                        method: 'post',
                        page: {
                            curr: 1
                        },
                        where: {
                            mgrId: mgrId,
                            cityId: cityId,
                            mgrName:mgrName
                        }
                    });
                    layer.close(index);
                }

            });

            //根据城市ID查询项目
            function selectMgrInfo(cityId) {
                var data;
                var url = '/util/findByCityId?cityId=' + cityId;
                $.ajax({
                        type: 'post',
                        async: false,
                        url: url,
                        success: function (json) {
                            data = json.data;
                        }, error: function () {
                            layer.msg('系统异常，请联系管理员处理!');
                        }
                    }
                );
                return data;
            }

            //监听项目
            form.on('select(cityId)', function (data) {
                var data = selectMgrInfo(data.value);
                appendMgr(data);
            });

            //动态拼接项目
            function appendMgr(data) {
                if (data.length != null) {
                    var options = '<option value="">请选择</option>';
                    for (var i = 0; i < data.length; i++) {
                        options += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
                    }
                    $('#mgrId').html(options);
                } else {
                    $('#mgrId').html('<option value="">该地市下没有项目</option>');
                }
                form.render();
            }

            //监听工具条
            table.on('tool(table)', function (obj) {
                var data = obj.data;
                if(data.templateState==2) {
                    if (obj.event == 'configure') {
                        if (isNull(data.content)) {
                            location.href="smsContentConfigure.html?mgrId="+data.id+
                            "&cityId="+data.cityId;
                        } else {
                            layer.msg("该项目已经有内容了，请点击 '短信内容修改'来修改它");
                        }
                    } else if (obj.event == 'modify') {
                        if (isNull(data.content)) {
                            layer.msg("该项目之前还没有配置过内容，请配置");
                        } else {
                            location.href="smsContentModify.html?mgrId="+data.id;
                        }
                    }
                }
                else {
                    layer.msg("未通过审核的项目无法配置内容");
                }
            });

        });
    </script>
    <script type="text/html" id="barDemo">
        <a href="#" lay-event="configure">短信内容配置</a>
        <a href="#" lay-event="modify">短信内容修改</a>
    </script>
</head>
<body>
<div class="layui-content-body">
    <div class="scroll-box">
        <div class="breadcrumb-box">
              <span class="layui-breadcrumb" lay-separator="|">
   <a href="javascript:returnIndex2()">首页&nbsp;</a>
  <a href="">短信内容配置管理</a>
</span>
        </div>
        <div class="content-box">
            <div class="form-select-box">
                <div class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">省份</label>
                            <div class="layui-input-block" style="width:110px">
                                <input type="text" name="province" lay-verify="required" value="江苏"
                                       autocomplete="off" class="layui-input" disabled>
                            </div>
                        </div>
                        <div class="layui-inline" >
                            <label class="layui-form-label">地市</label>
                            <div class="layui-input-block" style="width:110px">
                                <select name="cityId" lay-filter="cityId" id="cityId">
                                    <option value="">请选择</option>
                                    <option value="11">苏州</option>
                                    <option value="12">淮安</option>
                                    <option value="13">宿迁</option>
                                    <option value="14">南京</option>
                                    <option value="15">连云港</option>
                                    <option value="16">徐州</option>
                                    <option value="17">常州</option>
                                    <option value="18">镇江</option>
                                    <option value="19">无锡</option>
                                    <option value="20">南通</option>
                                    <option value="21">泰州</option>
                                    <option value="22">盐城</option>
                                    <option value="23">扬州</option>
                                    <option value="25">省级</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">项目名称</label>
                            <div class="layui-input-block">
                                <select name="mgrId" lay-filter="mgrId" id="mgrId">
                                </select>
                            </div>
                        </div>
                        <div id ="shortname" class="layui-inline" >
                            <label class="layui-form-label">项目简称</label>
                            <div class="layui-input-block">
                                  <input type="text" name="mgrName" lay-verify="required" id ="mgrName"
                                       autocomplete="off" class="layui-input"  >
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-normal" id="query">查询</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-table">
                <table id="table" lay-filter="table"></table>
            </div>
        </div>
    </div>
</div>
</body>
</html>